/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.click.app.dao.hibernate;

import com.click.app.Functions;
import com.click.app.dao.MaterialDao;
import com.click.app.model.LabelValue;
import com.click.app.model.Material;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author orgale
 */
public class MaterialDaoHibernate extends GenericDaoHibernate<Material, Long> implements MaterialDao {
    List<LabelValue> materialLabelValueList;
    public MaterialDaoHibernate() {
        super(Material.class);
    }

    public List<Material> findById(Long id) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public List<LabelValue> getAllLabelValue() {
        if(materialLabelValueList == null){
           List<Material> listMaterials = getAll();
           materialLabelValueList = new ArrayList<LabelValue>();
           for(Material m : listMaterials){
                materialLabelValueList.add(new LabelValue(m.getName(), m.getId().toString()));
           }
        }
        return materialLabelValueList;
    }
    public List<Material> findMaterialByDistintive( List<String> names, List<String> operatorNames
                                                  , List<String> values, List<String> operatorValues
                                                  , List<String> joinsFields){
      
       List listMaterials = getHibernateTemplate().find(" from Material material inner join fetch material.distinctives as distinctive "+
                                                        " where "+Functions.generateFilter( names, operatorNames
                                                                                           , values, operatorValues , "distinctive.name", "distinctive.value", joinsFields));
       return listMaterials;
    }

}
